/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.ambimmort.shj.action.logmanage.nn;

import cn.net.greenet.common.db_service.ConfigManager;
import com.j256.ormlite.jdbc.JdbcConnectionSource;
import com.j256.ormlite.support.ConnectionSource;

import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Administrator
 */
public class DBUtils {
    
    private static final String jdbc = ConfigManager.getInstance().getString("c3p0.jdbcUrl");
    private static final String username = ConfigManager.getInstance().getString("c3p0.user");
    private static final String password = ConfigManager.getInstance().getString("c3p0.password");

    public static ConnectionSource getConnectionSource() throws SQLException {
        JdbcConnectionSource connectionSource = new JdbcConnectionSource(jdbc, username, password);
        return connectionSource;
    }

    public static void closeConnectionSource(ConnectionSource conn) {
        if (conn != null) {
            try {
                conn.close();
            } catch (SQLException ex) {
                Logger.getLogger(DBUtils.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    }
    
}
